package ru.onlinestore.mobile.ui.primary

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.compose.rememberNavController
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.compose.KoinApplication
import org.koin.core.logger.Level
import ru.onlinestore.mobile.di.dataModule
import ru.onlinestore.mobile.di.domainModule
import ru.onlinestore.mobile.di.networkModule
import ru.onlinestore.mobile.di.viewModelsModule
import ru.onlinestore.mobile.ui.navigation.bottomNavigation.BottomNavigation
import ru.onlinestore.mobile.ui.navigation.bottomNavigation.NavigationGraph
import ru.onlinestore.mobile.ui.theme.white

@Composable
@Preview(
    showBackground = true,
    device = "id:Xiaomi POCO M5s"
)
private fun PrimaryScreenPreview() {
    val context = LocalView.current.context
    KoinApplication(
        application = {
            androidContext(context)
            modules(
                dataModule,
                domainModule,
                viewModelsModule,
                networkModule
            )
            androidLogger(Level.DEBUG)
        },
        content = {
            PrimaryScreen()
        }
    )
}

@Composable
fun PrimaryScreen() {
    val navController = rememberNavController()
    Scaffold(
        containerColor = white,
        content = {
            Column(
                content = {
                    NavigationGraph(controller = navController)
                },
                modifier = Modifier
                    .padding(it)
                    .fillMaxSize()

            )
        },
        bottomBar = {
            BottomNavigation(navigation = navController)
        }
    )
}